<template>
  <div class="spec-preview">
    <img :src="props.image" alt="" />
    <!-- 绑定事件区域 -->
    <div class="event" @mousemove="move"></div>
    <!-- 大图 -->
    <div class="big">
      <img
        :src="props.image"
        :style="{ left: -2 * left + 'px', top: -2 * top + 'px' }"
        alt=""
      />
    </div>
    <!-- 小灰 -->
    <div class="mask" :style="{ left: left + 'px', top: top + 'px' }"></div>
  </div>
  <div class="imageList">
    <div class="img-item" v-for="img in props.imageList" :key="img.id">
      <img class="active" :src="img.imgUrl" alt="" />
    </div>
  </div>
</template>
<script lang="ts">
export default {
  name: "ShopZoom",
};
</script>
<script lang="ts" setup>
import { ref } from "vue";
// import type { SkuImgListModel } from "@/api/model/detailModel";
const props = defineProps(["image", "imageList"]);
let left = ref(0);
let top = ref(0);

const move = (e: any) => {
  left.value = e.offsetX - 112.5;
  top.value = e.offsetY - 112.5;

  if (left.value < 0) left.value = 0;
  else if (left.value > 225) left.value = 225;

  if (top.value < 0) top.value = 0;
  else if (top.value > 225) top.value = 225;
};
</script>
<style lang="less">
.spec-preview {
  position: relative;
  width: 450px;
  height: 450px;

  img {
    width: 100%;
    height: 100%;
    border-radius: 10px;
  }

  .event {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
  }
  .mask {
    width: 50%;
    height: 50%;
    background-color: rgba(249, 250, 249, 0.3);
    position: absolute;
    left: 0;
    top: 0;
    display: none;
  }

  .big {
    width: 100%;
    height: 100%;
    position: absolute;
    top: -1px;
    left: 110%;
    border: 1px solid #aaa;
    overflow: hidden;
    z-index: 1;
    display: none;
    background: white;

    img {
      width: 200%;
      max-width: 200%;
      height: 200%;
      position: absolute;
      left: 0;
      top: 0;
    }
  }

  .event:hover ~ .mask,
  .event:hover ~ .big {
    display: block;
  }
}

.imageList {
  width: 453px;
  height: 100px;
  margin-top: 10px;
  display: flex;
  justify-content: space-between;

  .img-item {
    height: 68px;
    width: 68px;
    border-radius: 6px;

    img {
      width: 100%;
      height: 100%;
      border-radius: 6px;

      &.active {
        border: 2px solid #f60;
        padding: 1px;
      }

      &:hover {
        border: 2px solid #f60;
        padding: 1px;
      }
    }
  }
}
</style>
